/**
 * Created by fdg348 on 2017/11/7.
 */
ajaxShow();
//新闻动态列表页
function ajaxShow() {
    var paging = 1;
    // dropload函数接口设置
    $('#about_news_list').dropload({
        scrollArea: window,
        domDown: {
            domClass: 'dropload-down',
            // 滑动到底部显示内容
            domRefresh: '<div class="dropload-refresh"><span class="loading"></span></div>',
            // 内容加载过程中显示内容
            domLoad: '<div class="dropload-load"><span class="loading"></span></div>',
            // 没有更多内容-显示提示
            domNoData: '<div class="dropload-noData">暂无数据</div>'
        },
        // 下拉刷新模块显示内容
        loadDownFn: function (me) {
            paging++; // 每次请求，页码加1
            getNewsList(me,paging);
        },
        threshold:100
    });
}

function getNewsList(me,paging){
	var news_date = $('#news_date').val();
  	var article_classification = $('#article_classification').val();
	$.ajax({
        type: 'post',
        url: '/article/get-news-list',
        data: {news_date:news_date,article_classification:article_classification,paging:paging},
        dataType: 'json',
        success: function (data) {
        	if(data.code == 200){
        		var result = data.val;
                // 选择需要显示的数据 拼接 DOM
                if(result.length==0){
                	if(me != ''){
                		me.lock();
                        me.noData();
                        me.resetload();
                	}
                }else {
                	var host_url = $('#host_url').val();
                    var html = '';
                    var image_bath_url = $('#image_bath_url').val();
                    for (var i = 0; i < result.length; i++) {
                        html +='<li class="item">' +
                            '<img src="'+image_bath_url+result[i].article_pic+'" alt="" class="fl"/>' +
                            '<div class="item_info fr"> ' +
                            '<a target=_blank href="/article/news-detail?news_id='+result[i].id+'" class="link">'+result[i].article_title+'</a> ' +
                            '<p class="item_time">发布时间:<time>'+result[i].edit_time+'</time></p>' +
                            ' <p class="item_info_p">'+result[i].summary+'</p>' +
                            ' </div>' +
                            ' </li>'
                    }
                    setTimeout(function () {
                    	if(paging == 1){
                    		$('.about_news_list ul').html(html);
                    	}else{
                    		$('.about_news_list ul').append(html);
                    	}
                        if(me != ''){
                        	me.resetload();
                        }
                    }, 500);
                    if(me != ''){
                    	me.resetload();
                    }
                }
        	}else{
        		alert(data.val);
        	}
        },
        error: function (xhr, type) {
            console.log('加载出错了!');
            if(me != ''){
            	me.resetload();
            }
        }
    });
}

$(function(){
	getNewsList('',1);
});